package com.oreilly.ez.repo;

import com.oreilly.ez.entity.Study;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;


public interface StudyRepo extends JpaRepository<Study, Integer>{


    @Query("select s from Study  s " +
            "where s.enrollment.sid = :stuId " +
            "and s.courseTerm.sid = :termId")
    Study findByStuIdAndTermId(@Param("stuId") Integer stuId, @Param("termId") Integer termId);

    /**
     *
     * @param termId
     * @return
     */
    @Query("select s from Study s " +
            "where s.courseTerm.sid = :termId")
    List<Study> findByTermId(@Param("termId") Integer termId);


    @Query("select s from Study s " +
            "where s.enrollment.sid = :stuId")
    List<Study> findByStuId(@Param("stuId") Integer stuId);
}
